<?php
// comment/Form/Comment.php

class comment_Form_Comment extends Zend_Form
{

    protected $_noDecorator = array(
        'ViewHelper', 
        'Errors'
    );

    public function cluBuild($params)
    {
        // set the method for the display form to POST
        $this->setAttrib('id', 'new_comment');
        $this->setMethod('POST');
		$this->setAction($params['action_url']);
		
        $filterTrim = new Zend_Filter_StringTrim();
        $filterHtmlBody = new Clu_Filter_HtmlBody();
        $this->addElementPrefixPath('Clu_Filter', 'Clu/Filter/', 'filter');

        $sess = new Zend_Session_Namespace(CLU_NS);
        

        //poster_name and email if anonymous
        if (!$sess->userId)
        {
	        $poster_name = new Zend_Form_Element_Text('poster_name', 
	                         array('disableLoadDefaultDecorators' => true,
	                         //	   'required'   => true, 
	                               'class' => 'inputText'));
	        
	        $poster_name->addDecorators($this->_noDecorator);
	        $this->addElement($poster_name);
	        
	        //add guest email
	        $guest_email = new Zend_Form_Element_Text('guest_email', 
	                         array('disableLoadDefaultDecorators' => true,
	                             //  'required'   => true,
	                               'class' => 'inputText'));
	        
	        $guest_email->addDecorators($this->_noDecorator)
	        			->addFilter($filterTrim);
	        $this->addElement($guest_email);
        }
        
        //add title
        if ($params['content_type'] != 'user')
        {
	        $title = new Zend_Form_Element_Text('title', 
	                         array('disableLoadDefaultDecorators' => true,
	//                               'required'   => true,             
	                               'class' => 'inputText'));
	        
	        $title->addDecorators($this->_noDecorator);
	        $this->addElement($title);
        }
        //add rating
//        $rating = new Zend_Form_Element_Select('rating',  
//                         array('disableLoadDefaultDecorators' => true));
//        $rating->addMultiOption('all',t(61));
//        for($i = 1; $i <=  Zend_Registry::get('configuration')->rateMax; $i++)
//        	$rating->addMultiOption($i,$i);
//        $rating->addDecorators($this->_noDecorator);
//        $this->addElement($rating);
        
 		//language
 		$language = new Zend_Form_Element_Select('language',  
                         array('disableLoadDefaultDecorators' => true,
                             //   'required' => true
                         )); 
        $language->addMultiOption('vi',t(40))
                   ->addMultiOption('en',t(41))
                   ->addMultiOption('cn',t(42))
                   ->addMultiOption('jp',t(43))
               ->addDecorators($this->_noDecorator);
        $this->addElement($language);
        
        //add comment status
        $status = new Zend_Form_Element_Select('status',  
                         array('disableLoadDefaultDecorators' => true,
//                                'required' => true
                         )); 
        $status->addMultiOption('published',t(34))
               ->addMultiOption('queued',t(35))
               ->addMultiOption('unpublished',t(36))
               ->addMultiOption('deleted',t(37))
               ->addMultiOption('spam',t(116))
               ->addDecorators($this->_noDecorator);
        $this->addElement($status);
/*	
		if($params['control'] == 'ajax' && $params['content_type'] != 'user' )
        {
            //add check captcha
            $elementCaptcha =  new Zend_Form_Element_Captcha('captcha_newcomment',
                               array('captcha' => 'Image','captchaOptions' =>
                               array(
                                    'captcha' => 'Image',
                                    'wordLen' => 4,
                                    'timeout' => 300,
                                    'imgDir'  =>APP_PATH.'/public/captcha',
                                    'imgUrl' => '/public/captcha/',
                                    'width' => 175,
                                    'height' => 60,
                                    'font' => APP_PATH.'/public/captcha/font/tahoma.ttf',
                                    'DotNoiseLevel' => 1,  
                                    'LineNoiseLevel' => 0,
                                    'expiration' => 1,
                                    'gcFreq' => 1))
            );
            $elementCaptcha->setAttrib('id','captcha_newcommentImage')
                       	   ->setRequired(true);
            //$elementCaptcha->addDecorators($this->_noDecorator);
            //$elementCaptcha->setSeparator(" ");
            //die_a(get_class_methods($elementCaptcha));
            $elementCaptcha->removeDecorator("label")
            				->removeDecorator("htmlTag")
            				->removeDecorator("description");
            //die_a($elementCaptcha->getDecorators());
            
            $this->addElement($elementCaptcha);
        }
*/        
        //fck
        $width = get_key('comment_' . SITE .'_' . $sess->userTheme . '_' . $params['content_type'] . '_region' . $params['region'] . '_fck_width');
        $height = get_key('comment_' . SITE .'_' . $sess->userTheme . '_' . $params['content_type'] . '_region' . $params['region'] . '_fck_height');

        if ((!$width) && (!$height))
        {
        	//comment_hvn_hard_default_regionx_fck_width;
        	$width = get_key('comment_' . SITE .'_' . $sess->userTheme . '_default_regionx_fck_width');
        	$height = get_key('comment_' . SITE .'_' . $sess->userTheme . '_default_regionx_fck_height');
        
        }
        $fck = new Clu_Form_Element_FckEditor('comment_text', array(
        		'fckOptions' => array (
        						'Width'  => $width,
        						'Height' => $height,
        						'ToolbarSet' => 'Comment'
        					)
       			 )
        );
        $fck->setLabel(t(606));
        if (strpos($sess->userPermissions, "administer") === false)
        	$fck->addFilter($filterHtmlBody ); 
        $this->addElement($fck);

        $label = '';
     	if($params['action'] == 'new')
     		$label = t(58);
     	else if($params['action'] == 'update')
     		$label = t(59);
	    $submit = new Zend_Form_Element_Submit('submit', array('disableLoadDefaultDecorators' => true,
	        														'id' => 'submit_comment', 
	                                                               'label' => $label ));
        $submit->addDecorators($this->_noDecorator);
    	$this->addElement($submit);
    }
}
